﻿using ArtheaEngine;
using NLog;

namespace ArtheaServer.Commands
{
    public class DeleteCommand : Command
    {
        private static readonly Logger log = LogManager.GetCurrentClassLogger();

        public DeleteCommand() : base("delete", "Deletes your characters.")
        {
        }

        #region Overrides of Command

        public override void Execute(Character ch, Argument argument)
        {
            if (!(ch is Player))
                return;

            var p = ch as Player;

            if (!p.Account.Password.ToArray().DeepCompare(World.Encoding.GetBytes(argument.ToString())))
            {
                p.WriteLine("Syntax: {0} <account password>", Name);
                return;
            }
            World.DataContext.Characters.DeleteOnSubmit(p);
            World.DataContext.SubmitChanges();
            p.WriteLine("Good-bye!");

            log.Info(p.Name + " has deleted");
            throw new QuitCommandException();
        }

        #endregion
    }
}